$(document).ready(function() {
	try {
		$('#example').dataTable();
	} catch (err) {
		console.log(err);
	}
	
	$('#from-date').datepicker();
	$('#to-date').datepicker();
	MC.SpendModel = Backbone.Model.extend();
	MC.SpendCollection = Backbone.Collection.extend({
		model : MC.SpendModel
	});
	MC.spendCollection = new MC.SpendCollection();
	MC.spendCollection.reset(MC.monthlySpending);

	// Format the spendCollection to use in chart
	var xAxis = MC.spendCollection.at(0).get('time') || [];
	var yAxis = [];
	_.each(MC.spendCollection.models, function(model) {
		console.log(model);
		var point = {};
		point.name = model.get('bank').name + " - " + model.get('card').brand;
		point.data = model.get('spending');
		yAxis.push(point);
	});

	MC.monthlyChart('chart_div', 'column', xAxis, yAxis);
	
	$(document).ajaxStart(function(){
		$('.updating-label').removeClass('hidden');
	});
	
	$(document).ajaxStop(function(){
		$('.updating-label').addClass('hidden');
	});
});